
package com.jimo.qrcode.dto;

import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
import com.jimo.qrcode.constants.QrCodeConstants;
import com.jimo.qrcode.utils.ObjectUtils;

/**
 * Title: QRCodeDto
 * Description: 
 * @author JIMO
 * @date 2019年6月4日
 */
public class QRCodeDto {
	/** 二维码文件名 */
	private String fileName;
	/** 二维码内容 */
	private String content;
	/** 二维码中间logo相关信息 */
	private QRCodeLogoDto logo;
	
	/** 二维码尺寸（默认300px） */
    private Integer size = 300;
    /** 描点颜色 默认黑色 */
    private int color = 0xFF000000;
    /** 背景颜色 默认白色 */
    private int backgroundColor = 0xFFFFFFFF;
    /** 边框距 默认为1*/
    private Integer margin = 1;
    /** 字符集编码格式 默认为utf-8 */
    private String charset = "utf-8";
    /** 图片格式，默认为jpg */
    private String format = "JPG";
    /** 设置容错等级，默认使用M级别 */
    private ErrorCorrectionLevel errorCorrection = ErrorCorrectionLevel.M;
    /** 生成二维码存放的地址 默认为当前工程对应磁盘的 home/common/QRcode文件夹下 */
    private String destPath = "/home/tmp/QRcode";

	public String getFileName() {
		// 获得filename的后缀名
		String extension = fileName.substring(fileName.lastIndexOf(QrCodeConstants.POINT) + 1);
		if (ObjectUtils.isEmpty(extension) || !extension.toUpperCase().equals(format)) {
			// 如果没有后缀，加上后缀
			// 如果后缀与文件格式不匹配，强制将后缀改成文件格式
			return fileName + QrCodeConstants.POINT + format;
		}
		return fileName;
	}

	public QRCodeDto setFileName(String fileName) {
		this.fileName = fileName;
		return this;
	}

	/**
	 * @return the content
	 */
	public String getContent() {
		return content;
	}
	/**
	 * @param content the content to set
	 * @return this;
	 */
	public QRCodeDto setContent(String content) {
		this.content = content;
		return this;
	}
	/**
	 * @return the logo
	 */
	public QRCodeLogoDto getLogo() {
		return logo;
	}
	/**
	 * @param logo the logo to set
	 * @return this;
	 */
	public QRCodeDto setLogo(QRCodeLogoDto logo) {
		this.logo = logo;
		return this;
	}
	/**
	 * @return the size
	 */
	public Integer getSize() {
		return size;
	}
	/**
	 * @param size the size to set
	 * @return this;
	 */
	public QRCodeDto setSize(Integer size) {
		this.size = size;
		return this;
	}
	/**
	 * @return the color
	 */
	public int getColor() {
		return color;
	}
	/**
	 * @param color the color to set
	 * @return this;
	 */
	public QRCodeDto setColor(int color) {
		this.color = color;
		return this;
	}
	/**
	 * @return the backgroundColor
	 */
	public int getBackgroundColor() {
		return backgroundColor;
	}
	/**
	 * @param backgroundColor the backgroundColor to set
	 * @return this;
	 */
	public QRCodeDto setBackgroundColor(int backgroundColor) {
		this.backgroundColor = backgroundColor;
		return this;
	}
	/**
	 * @return the margin
	 */
	public Integer getMargin() {
		return margin;
	}
	/**
	 * @param margin the margin to set
	 * @return this;
	 */
	public QRCodeDto setMargin(Integer margin) {
		this.margin = margin;
		return this;
	}
	/**
	 * @return the charset
	 */
	public String getCharset() {
		return charset;
	}
	/**
	 * @param charset the charset to set
	 * @return this;
	 */
	public QRCodeDto setCharset(String charset) {
		this.charset = charset;
		return this;
	}
	/**
	 * @return the format
	 */
	public String getFormat() {
		return format;
	}
	/**
	 * @param format the format to set
	 * @return this;
	 */
	public QRCodeDto setFormat(String format) {
		this.format = format;
		return this;
	}
	/**
	 * @return the errorCorrection
	 */
	public ErrorCorrectionLevel getErrorCorrection() {
		return errorCorrection;
	}
	/**
	 * @param errorCorrection the errorCorrection to set
	 * @return this;
	 */
	public QRCodeDto setErrorCorrection(ErrorCorrectionLevel errorCorrection) {
		this.errorCorrection = errorCorrection;
		return this;
	}
	/**
	 * @return the destPath
	 */
	public String getDestPath() {
		return destPath;
	}
	/**
	 * @param destPath the destPath to set
	 */
	public QRCodeDto setDestPath(String destPath) {
		this.destPath = destPath;
		return this;
	}
}
